//
//  operator_overload.cpp
//  learnC++
//
//  Created by liuzhibing on 2018/6/9.
//  Copyright © 2018年 yunfan.com. All rights reserved.
//

#include "operator_overload.hpp"

OperatorOverload::OperatorOverload(int value){
    m_value = value;
}

//重载2元运算符+、-
OperatorOverload operator+(const OperatorOverload &ov1,const OperatorOverload &ov2){
    
    return OperatorOverload(ov1.m_value+ov2.m_value);
}

OperatorOverload operator-(const OperatorOverload &ov1,const OperatorOverload &ov2){
    return OperatorOverload(ov1.m_value-ov2.m_value);
}

//重载1元运算符+、-
OperatorOverload OperatorOverload::operator+() const{
    
    int temp = m_value >0 ? m_value : -m_value;
    return OperatorOverload(temp);
}

OperatorOverload OperatorOverload::operator-() const{
    int temp = m_value >0 ? -m_value : m_value;
    return OperatorOverload(temp);
}

std::ostream &operator<<(std::ostream &out,const OperatorOverload &ov){
    out << ov.m_value << std::endl;
    return out;
}

OperatorOverload &OperatorOverload::operator=(const OperatorOverload &ov){
    m_value = ov.m_value;
    return *this;
}

OperatorOverload::OperatorOverload(const OperatorOverload &ov){
    m_value = ov.m_value;
}

int OperatorOverload::operator[](int index){
    
    return m_value/*[index]*/;
}

int & OperatorOverload::operator()(int row,int col){
//    m_value = row + col;
    return m_value/*[row][col]*/;
}

OperatorOverload &OperatorOverload::operator+=(int value){
    m_value += value;
    return *this;
}

OperatorOverload::operator int() const{
    return m_value;
}
